/*
 * NetworkClient.h
 *
 *  Created on: Apr 12, 2011
 *      Author: Alan Mattila
 */

#ifndef NETWORKCLIENT_H_
#define NETWORKCLIENT_H_

#define NETWORK_ILLEGAL_MOVE 2

#include <QObject>
#include <QTcpSocket>

#include "Network.h"
#include "Packet.h"
#include "../board/Board.h"

using std::string;

class NetworkClient : public Network
{
	Q_OBJECT

public:
	// Constructor/destructor functions
	NetworkClient();
	NetworkClient(string _hostname);
	~NetworkClient();

	Board *GetBoard() const { return board; };
	int GetStatus() const { return status; };
	QTcpSocket* GetTcpSocket() const {return tcpSocket; };

public slots:
	int ConnectToServer();
	int GetPacketFromServer();
	int UpdateBoard();
	int MakeMove(int x1, int y1, int x2, int y2);
	void ReadyRead(void);
	void Error(void);
	void Disconnected(void);

signals:
	void gameBoardReceived(void);
	void messageReceived(packetMessage_t);

private:
	Board *board;
	int status;

	QTcpSocket *tcpSocket;
	quint8 blockSize;

private slots:
	int ParsePacket();
};


#endif /* NETWORKCLIENT_H_ */
